home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: receive.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:55:54 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "thread.h"
- #include "semaphore.h"
- #include "link.h"
- #include "host.h"
- #include "msgvector.h"
- #include "threadstate.h"
- #include "bitvec.h"
- #include "msg_funcs.h"
- #include "thread_funcs.h"
-
- int
- receive (
-
- register LINK *link,
- register char *buffer,
- register int readBytes
- )
- {
-
- register int bytesRead;
- register int remainBytes;
- register int totalBytes;
-
-
- TRPRINT(TR_MSG, TR_LEVEL_1, ("reading link:%d readBytes:%d", link->id, readBytes));
-
- #ifdef DEBUG
- /*
- * Make sure that if we're not reading in a message header
- * then the buffer is not in the thread.
- */
- if (readBytes > sizeof(MESSAGE)) {
- SM_ASSERT(LEVEL_1, buffer != (char*)&(Active->message));
- }
- #endif
-
- /*
- * read the messages, repeatedly perhaps
- */
- for (totalBytes = 0; totalBytes < readBytes; totalBytes += bytesRead) {
-
- /*
- * calculate remaining bytes
- */
- remainBytes = readBytes - totalBytes;
- SM_ASSERT(LEVEL_3, remainBytes > 0);
- TRPRINT(TR_MSG, TR_LEVEL_2, ("want to read:%d", remainBytes));
-
- /*
- * read the remaining bytes
- */
- bytesRead = read(link->id, buffer + totalBytes, remainBytes);
- TRPRINT(TR_DISK, TR_LEVEL_2, ("bytesRead:%d", bytesRead));
-
- /*
- * check to see we read more data than we want
- */
- SM_ASSERT(LEVEL_3, bytesRead <= remainBytes);
-
- /*
- * check to see if was an error or a close
- */
- if (bytesRead < 0) {
-
- SM_ERROR(TYPE_SYS, errno);
- }
-
- /*
- * check to see if eof
- */
- if ((bytesRead == 0) || (bytesRead < 0)) {
-
- /*
- * shut down the link
- */
- switch (link->linkClass) {
-
- case CL_DGRAM:
- case CL_CONNECT:
- case CL_DISK:
-
- SM_ERROR(TYPE_CRASH, esmINTERNAL);
- break;
-
- case CL_CLIENT:
-
- freeClientLink(link);
- return(esmFAILURE);
- break;
-
- default:
-
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
- break;
- }
-
- } else if (bytesRead < remainBytes) {
-
- /*
- * put ourselves on the read queue for the link
- */
- waitList( &(link->tcbList), THREAD_RECEIVE_WAIT );
-
- }
- }
- incPages(readBytes, RECEIVED, FALSE); /* MsgStats */
- return esmNOERROR;
- }
-